package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrdermmMapper {
    /*
     * 客户端查询
     * */
    Page<Orders> listhistorder(OrdersPageQueryDTO ordersPageQueryDTO);

/*
* 查询状态数量
* */
    @Select("select " +
            "count(status = 2 OR NULL) AS toBeConfirmed," +
            "count(status = 4 OR NULL) AS deliveryInProgress," +
            "count(status = 3 OR NULL) AS confirmed from orders")
    OrderStatisticsVO listcount();


    /*
* 接单加派送
* */
    void updateByid(Orders orders);


    /*
* 拒单
* */
    void  jiedanupdate(Orders orders);
/*
* 取消订单
* */
    @Update("update orders set cancel_reason=#{cancelReason},status=#{status},cancel_time=#{cancelTime} where id=#{id}")
    void cancel(Orders orders);
/*
* 已完成
* */
    @Update("update orders set status=#{status} where id=#{id}")
    void finish(Orders orders);
/*
* 根据id查询订单
* */
    @Select("select * from orders where id=#{id}")
    OrderVO selecttBid(long id);
/*
* 查询超时订单
* */
    @Select("select * from orders where status=#{paid} and order_time<#{time}")
    List<Orders> scelectTimeout(Integer paid, LocalDateTime time);
}
